package com.chapter.sample;

import com.alibaba.druid.pool.DruidDataSource;
import com.chapter.sample.dao.UserDao;
import com.chapter.sample.service.UserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Date;
import java.util.Map;

public class ApplicationContextTest {
    public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("application.xml");

//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setDriverClassName();
//        dataSource.setUrl();
//        dataSource.setUsername();
//        dataSource.setUrl();

//        Class<?> aClass = Class.forName("com.mysql.jdbc.Driver");
//        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis", "root", "root");


//        Object dataSource = applicationContext.getBean("dataSource");
//        System.out.println(dataSource);
//
//        Object connection = applicationContext.getBean("connection");
//        System.out.println(connection);
//
//        Object person = applicationContext.getBean("personDao");
//        System.out.println(person);
//
//        Object otherBean = applicationContext.getBean("otherBean");
//        System.out.println(otherBean);
        //=================================
        /*//静态工厂方法
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
        //无参构造方法
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        //实例构造方法
        SqlSessionFactory build = builder.build(in);

        Object sqlSessionFactory = applicationContext.getBean("sqlSessionFactory");
        System.out.println(sqlSessionFactory);*/

//        UserDao userDao = (UserDao) applicationContext.getBean("userDao");
//        userDao.show();

        UserService userService = (UserService) applicationContext.getBean("userService");
        userService.show();


    }
}
